<template>
  <div class="page_order" id="order_list">
    <div class="warp">
      <div class="container">
        <div class="row">
          <div class="col-10">
            <div class="card_goods_list">
              <h4>我的订单</h4>
              <list_order
                v-if="$check_action('/order/list', 'get')"
                :list="list_diff"
              ></list_order>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import list_order from "../../components/diy/list_order.vue";
import mixin from "../../mixins/page.js";

export default {
  mixins: [mixin],
  components: {
    list_order,
  },
  data() {
    return {
      // 登录权限
      oauth: {
        signIn: true,
        user_group: [],
      },
      url_get_list: "~/api/order/get_list",
      list_diff: [],
      query: {
        user_id: 0,
      },
    };
  },
  methods: {
    get_list_before(param) {
      param.user_id = this.user.user_id;
      return param;
    },
    get_list_after(json) {
      // 根据订单号区分列表
      var list_diff = [];
      var order_num = "";
      var index = -1;
      json.result.list.map((o) => {
        if (o.order_number === order_num) {
          list_diff[index]["list"].push(o);
          list_diff[index]["sum_price"] += o.price_count;
        } else {
          index += 1;
          order_num = o.order_number;
          list_diff[index] = {};
          var obj_diff = list_diff[index];
          obj_diff["create_time"] = o.create_time;
          obj_diff["order_number"] = order_num;
          obj_diff["list"] = [];
          obj_diff["list"].push(o);
          obj_diff["sum_price"] = o.price_count;
          obj_diff["state"] = o.state;
        }
      });
      this.list_diff = list_diff;
      return json;
    },
  },
};
</script>

<style>
.page_order {
  background-color: #f8f8f8;
  min-height: 100vh;
}
</style>
